﻿Imports System.Data.SqlClient
Public Class ItensInventarioDAL
#Region "Incluir"
    Public Function inserir(inv_codigo As Integer, inv_qtdereal As Integer, pec_codigo As Integer, pec_qtde As Integer) As Integer
        Dim cmd = New SqlCommand
        Dim codigo As Integer
        Try
            cmd.CommandText = "insert into Estoque.Ofi_InventarioItens (inv_codigo,inv_qtdereal,pec_codigo,pec_qtde) values (@inv_codigo, @inv_qtdereal, @pec_codigo, @pec_qtde)"
            cmd.Parameters.Add(New SqlParameter("@inv_codigo", SqlDbType.Int)).Value = inv_codigo
            cmd.Parameters.Add(New SqlParameter("@inv_qtdereal", SqlDbType.Int)).Value = inv_qtdereal
            cmd.Parameters.Add(New SqlParameter("@pec_codigo", SqlDbType.Int)).Value = pec_codigo
            cmd.Parameters.Add(New SqlParameter("@pec_qtde", SqlDbType.Int)).Value = pec_qtde
            codigo = objconexao.executaCmd(cmd)
        Catch ex As Exception
            Throw ex
        Finally
            cmd = Nothing
        End Try
        Return codigo
    End Function
#End Region

#Region "Excluir"
    Public Function excluirtodositens(inv_codigo As Integer) As Integer
        Dim cmd = New SqlCommand
        Dim codigo As Integer
        Try
            cmd.CommandText = "delete from Estoque.Ofi_InventarioItens where inv_codigo=@inv_codigo"
            cmd.Parameters.Add(New SqlParameter("@inv_codigo", SqlDbType.Int, 1)).Value = inv_codigo
            codigo = objconexao.executaCmd(cmd)

        Catch ex As Exception
            Throw ex

        Finally
            cmd = Nothing

        End Try
        Return codigo
    End Function
#End Region

#Region "Buscar"
    Function buscar(ByVal descricao As String, tipo As Integer) As DataTable
        Dim cmd As SqlCommand
        Dim tab As DataTable
        Try
            cmd = New SqlCommand
            Select Case tipo
                Case 1
                    'por codigo
                    cmd.CommandText = "select pec_codigo, pec_codbarra, pro_descricao, pec_qtde, inv_qtdereal from vw_EstItensInventario where  inv_codigo= @codigo"
                    cmd.Parameters.Add(New SqlParameter("@codigo", SqlDbType.Int)).Value = Val(descricao)

                Case Else
                    'todos
                    cmd.CommandText = "select * from vw_EstItensInventario"


            End Select
            tab = objconexao.executaConsulta(cmd)
            tab.DefaultView.AllowNew = False
        Catch ex As Exception
            Throw ex
        Finally
            cmd = Nothing
        End Try
        Return tab
    End Function
#End Region
End Class
